<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<style>
    .table-border tbody tr td{
        border-top: 1px solid black;
    }
</style>
<section class="content-header">
    <h1>核算成本清单审核</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" class="form-horizontal">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        项目编号：
                                    </label>
                                    <label class="control-label">
                                        <input name="code" class="form-control" type="text" maxlength="255" value=""
                                               placeholder="请输入项目编号"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        项目名称：
                                    </label>
                                    <label class="control-label">
                                        <input name="name" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入项目名称"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        创建者：
                                    </label>
                                    <label class="control-label">
                                        <input name="userName" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入创建者"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        审核状态：
                                    </label>
                                    <label class="control-label">
                                        <select class="form-control" name="appStatus">
                                            <option value="0">请选择</option>
                                            <option value="1" selected="selected">未审核</option>
                                            <option value="2">已审核</option>
                                        </select>
                                    </label>
                                </div>
                                <button id="btn-search" type="button" class="btn btn-success pull-right">
                                    搜索
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" class="table-border"></table>
                </div>
            </div>
        </div>
    </div>
</section>

<div th:include="include :: footer"></div>

<script th:inline="javascript">
    /**
     * 表格对象
     **/
    let table;
    /**
     * 审核状态样式
     **/
    let statusClass = ["label-danger", "label-default", "label-success"];
    /**
     * 审核状态文本
     **/
    let statusText = ["审核驳回", "未审核", "审核通过"];
    /**
     * 审核级别样式
     **/
    let approvalLevelMap = new Map();
    approvalLevelMap.set("员工级", "bg-default color-palette");
    approvalLevelMap.set("组长级", "bg-aqua color-palette");
    approvalLevelMap.set("科长级", "bg-purple color-palette");
    approvalLevelMap.set("部长级", "bg-maroon color-palette");
    /**
     * 就绪函数
     **/
    $(function () {
        window.parent.getItemCount();
        $("#btn-search").on('click', function (e) {
            js.table.refresh(table);
        })
        /**
         * 加载列表
         */
        table = js.table.init({
            url: ctx + "accountManage/findApprovalList",
            showColumns: true,
            showExport: true,
            columns: [
                {
                    title: '序号', field: 'id', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: '项目编号', field: 'code',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '项目名称', field: 'name',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '创建者', field: "userName",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '创建时间', field: "startDate",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '提交时间', field: "submitDate",
                    formatter: function (value, row, index) {
                        return value;
                    }
                },
                {
                    title: '审核状态', field: 'appStatus',
                    formatter: function (value, row, index) {
                        return '<lable class="badge ' + statusClass[value] + '">' + statusText[value] + '</lable>';
                    }
                },
                {
                    title: '操作',
                    formatter: function (value, row, index) {
                        let elements = new Array();

                        if (row.appStatus === 1) {
                            elements.push('<button class="btn btn-warning btn-xs" onclick="approval(' + row.batId + ','+row.id+')">审核</button>');
                        }
                        return elements.join('');
                    }
                }
            ]
        });
        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });
    });

    /**
     * 审核
     */
    function approval(batId,id) {
        window.open(ctx + 'accountManage/showAccCostSheetByApproval/' + batId+'/'+id+'/see');
    }

    function reload(){
        js.table.refresh(table)
    }
</script>
</body>
</html>